47

Explore Your Deductive Logic—Sudoku

47

STEP 9 continued

      savedrow1 =​ i -​ 1

      savedrow2 =​ i +​ 1

    End If

    End If

    Call addtocantbelist(putnumber, savedrow1, savedcolumn(i))

    Call addtocantbelist(putnumber, savedrow1, savedcolumn(i) -​ 1)

    Call addtocantbelist(putnumber, savedrow1, savedcolumn(i) -​ 2)

    Call addtocantbelist(putnumber, savedrow2, savedcolumn(i))

    Call addtocantbelist(putnumber, savedrow2, savedcolumn(i) -​ 1)

    Call addtocantbelist(putnumber, savedrow2, savedcolumn(i) -​ 2)

End If

Next i

:

:

Next putnumber

Function findincantbelist(thisnumber, thisrow, thiscolumn)

findincantbelist =​ 0

For i =​ 1 To 8

    If cantbelist(thisrow, thiscolumn, i) <> 0 Then

      If cantbelist(thisrow, thiscolumn, i) =​ thisnumber Then

        findincantbelist =​ 1

      End If

STEP 9

    End If

Next i

End Function

STEP 10

This step is almost a repeat of the step 9, but now for columns. In step 9 we checked

the adjacency of grids horizontally. The same needs to be done vertically to get the

exclusion list prepared for the correct columns. The principle here is the same—​to

compare the cell with each of the nine numbers, one grid at a time. If the number

is found in cantbelist for a cell, or the cell is occupied by a number that is not the

same as the number being searched, then a count is kept to see how many cells are

there of this kind in that column. If there are 3, then it is a candidate, less than 3

does not qualify hence count is reset to zero for that grid. If the count is 6 for that

column, this means there are two out of the three adjacent grids that cannot have

this number. Hence the third grid included in this column must have this number.

Therefore, the other columns in this third grid cannot have this number—​these are

then added to the cantbelist.

For putnumber =​ 1 to 9

:

:

‘ *** algorithm to refine cantbelist based on one column of 3 by 3 grid

For i =​ 1 To 9

middlecolumncount(i) =​ 0